import os
import pandas


class OperationData(object):
    def __init__(self, file_name):
        base_path = os.path.dirname(os.path.dirname(__file__))
        data_path = os.path.join(base_path, 'Data')
        file_path = os.path.join(data_path, file_name)
        if file_path.endswith('xls') or file_path.endswith('xlsx'):
            self.table = pandas.read_excel(file_path, keep_default_na=False)
        elif file_path.endswith('csv'):
            self.table = pandas.read_csv(file_path, keep_default_na=False)
        else:
            print('请选择符合条件的文件,例如csv或xls')
            self.table = None

    def get_data_to_list(self):
        return self.table.values.tolist()

    def get_data_to_dict(self):
        return [self.table.loc[i].to_dict() for i in self.table.index.values]


if __name__ == '__main__':
    operation_data = OperationData(file_name="自动化测试数据.xlsx")
    print(operation_data.get_data_to_list())

    pass
